package ooday04.homework;

public class PolymorphicDemo {
    public static void main(String[] args) {
//        Master master = new Master();
//        Dog dog = new Dog("小黑",2,"黑");
//        Chick chick = new Chick("小花",3,"花");
//        Fish fish = new Fish("小金",1,"金");
//        master.feed(dog);
//        master.feed(chick);
//        master.feed(fish);


        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Dog("小白", 1, "白");
        animals[2] = new Fish("小金", 1, "金");
        animals[3] = new Fish("小花", 2, "花");
        animals[4] = new Chick("小灰", 3, "灰");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat(); //每个动物吃饭
            animals[i].drink(); //每个动物喝水
            if (animals[i] instanceof Dog) {
                Dog dog = (Dog) animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Chick) {
                Chick chick = (Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Swim) { //适用于所有实现Swim接口的(会游泳的)
                Swim s = (Swim) animals[i];
                s.swim();
            }
        }
    }

}
